package com.ny.mapper;

import com.ny.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user")
    public List<User> fillAllUser();
    //登录

    @Select("select * from user where username=#{username} and password=#{password}")
    public User login(@Param("username") String username, @Param("password") String password);
    //根据用户名查询用户
    @Select("select * from user where username=#{username}")
    public User findByUsername(@Param("username") String username);

    @Insert("INSERT INTO `user` (username, password, nickname, phone, email, is_active, created_time) " +
            "VALUES (#{username}, #{password}, #{nickname}, #{phone}, #{email}, #{is_active}, #{created_time})")
    @Options(useGeneratedKeys = true, keyProperty = "user_id")
    int insertUser(User user);

    @Select("SELECT * FROM user WHERE email = #{email}")
    public User findByEmail(@Param("email") String email);
    //根据邮箱修改密码
    @Update("UPDATE user SET password = #{password} WHERE email = #{email}")
    public int updatePasswordByEmail(@Param("email") String email, @Param("password") String password);

    // 根据用户名和加密后的密码查询用户
    @Select("select * from user where username= #{username} and password =#{password}")
    public User findUser(@Param("username") String username, @Param("password") String password);
}
